var express = require('express')
var router = express.Router()
// var mongoose=require('mongoose')

var TotalImage = require('../models/totalImage')

/************** 创建(create) 读取(get) 更新(update) 删除(delete) **************/
router.route('/displayImg').post((req, res) => {
    TotalImage.find( {"type":req.body.type},(err, totalImage) => {
        console.log({TotalImage},2);
        if (err) {
            console.log(err)
            res.json({
                status:'1'
            })
        }
        console.log(req.body)
        res.json({
            status:'0',
            results:{
                count:totalImage.length,
                list:totalImage
            }
        })
    })
})

router.get('/displayImg', (req, res) => {
    // 通过模型去查找数据库
    TotalImage.find((err, totalImage) => {
        if (err) {
            res.send(err);
        } else {
            console.log(req.body)
            res.send({
                    status:'0',
                    results:
                    {
                    count:totalImage.length,
                    list:totalImage
                    }
            });
        }
    });
});

module.exports = router